<?php

namespace app\api\model;

class ConfigPersonal extends Common
{
    static public function createData($user_id, $sex, $returnArray = false)
    {
        // if ($sex == '女') {
            // $configPrice = ConfigPrice::where(['id' => ['gt', 0]])->order('min_charm_grade desc, price desc')->column('types, price');
            $configPrice = ConfigSystem::index('chat');
        // } else {
            $configPrice = [
                'chat_price' => $configPrice['chat_price'],
                'voice_price' => $configPrice['voice_price'],
                'video_price' => $configPrice['video_price'],
                'voice_switch'=>1,
                'video_switch'=>1,
                'hide_distance'=>0,
                'hide_visit'=>0,
                'hide_ranking'=>0,
                'hide_family'=>0,
                'hide_defend_ranking'=>0,
                'hide_defend_angel'=>0,
                'hide_defends'=>0,
                'hide_charm'=>0,
                'hide_gift'=>0,
                'fate_switch'=>1,
                'fate_limit'=>0,
                'fate_realavatar_limit'=>0,
                'fate_realname_limit'=>0,
                'unsmstip_switch'=>1,
                'system_video_push_reject'=>0,
                'hide_experience'=>0,
                'hide_expertise'=>0,
                'is_read_rule'=>0,
                'chat_rule_agree'=>0,
            ];
        // }
        $user = User::find($user_id);
        // if (strtotime($user['register_datetime']) >= strtotime('2023-04-15 00:00:00')) {
        //     $configPrice = [
        //         'chat_price' => 0,
        //         'voice_price' => 0,
        //         'video_price' => 0,
        //     ];
        // }
        // $result = self::create([
        //     'user_id' => $user_id,
        //     'chat_price' => $configPrice['chat_price'],
        //     'voice_price' => $configPrice['voice_price'],
        //     'video_price' => $configPrice['video_price']
        // ]);
        if($sex=='女'){
            $result = self::create([
                'user_id' => $user_id,
                'chat_price' => $configPrice['chat_price'],
                'voice_price' => $configPrice['voice_price'],
                'video_price' => $configPrice['video_price'],
                'hide_distance' => 1,//女用户默认隐藏位置和距离
            ]);
        }elseif($sex=='男') {//男的不设置收费
            $result = self::create([
                'user_id' => $user_id,
                'chat_price' => 0,
                'voice_price' => 0,
                'video_price' => 0
            ]);
        }

        if ($returnArray) {
            return $configPrice;
        }

        $response = $result ? self::$returns['user.success.personalConfig'] : self::$returns['user.error.personalConfig'];

        return $response;
    }
}
